<!-- 地图 》 点位地图 -->

<template>
  <CommonBody v-bind="bodyProps" @change="toChange">
    <template #treeNode="{ data, nodeClass }">
      <AreaNode :data="data" :nodeClass="nodeClass" />
    </template>

    <div v-show="map_info.id" class="full">
      <MapView />
      <MySearch v-show="!map_param.deviceCategoryId" />
      <MyIOT v-show="map_param.deviceCategoryId && map_param.deviceCategoryId !== '24'" />
      <MyFirefighting v-show="map_param.deviceCategoryId === '24'" />
    </div>

    <MapEmpty v-show="map_readyInfo && !map_info.id">
      <BtnAdd title="绑定地图" :onClick="bind_openAdd" />
    </MapEmpty>

    <BindModal />
  </CommonBody>
</template>

<script>
// ============================== 导入依赖 ============================== //

import CORE from '@/CORE'
import mixMap from '@admin/views/Secure/mixMap'
import store from './store'

// ============================== 导出组件 ============================== //

export default {
  /**
   * 名称定义 (实际使用名称)
   */
  name: 'MapPoint',

  /**
   * 混入列表 (配置选项合并)
   */
  mixins: [mixMap('', store)],

  /**
   * 组件导入 (Abc.vue + Abc/index.vue)
   */
  ...CORE.components(require.context('./', true, /vue$/)),

  /**
   * 监听属性 (深度 deep 首次 immediate)
   */
  watch: {
    /**
     * 监听新增绑定
     */
    bind_readyAdd(ready) {
      ready && this.map_startInfo()
    },

    /**
     * 监听修改绑定
     */
    bind_readyEdit(ready) {
      ready && this.map_startInfo()
    },

    /**
     * 监听地图信息就绪
     */
    map_readyInfo(ready) {
      if (ready) {
        this.map_INIT_ONE.areaMapId = this.map_info.id
        this.map_setOne()
      }
    },

    /**
     * 监听点位新增就绪
     */
    map_readyAdd(ready) {
      ready && this.toReset()
    },

    /**
     * 监听点位修改就绪
     */
    map_readyEdit(ready) {
      ready && this.toReset()
    },

    /**
     * 监听点位删除就绪
     */
    map_readyDel(ready) {
      ready && this.toReset()
    },
  },

  /**
   * 销毁之前 (先抽取再调用)
   */
  beforeDestroy() {
    this.map_selectParam.deviceCategoryId = ''
  },

  /**
   * 本地方法 (轻量重要在前)
   */
  methods: {
    /**
     * 点击切换
     */
    toChange({ id }) {
      const { map_param, bind_INIT_ONE, map_INIT_ONE } = this

      bind_INIT_ONE.areaId = map_INIT_ONE.areaId = id
      bind_INIT_ONE.areaName = map_INIT_ONE.areaName = CORE.REGION.NAME[id]

      this.map_setOne()
      this.map_setList()
      this.map_startInfo()

      this.selectParam.nextIdList = map_param.deviceCategoryId ? [id] : []
      this.setSelect()
      this.startSelect()
    },

    /**
     * 重置一些状态
     */
    toReset() {
      if (this.map_GETTER.isLine) this.map_startSelect()
      this.map_setOne()
    },
  },
}
</script>
